define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'store/index',
                    add_url: 'store/add',
                    edit_url: 'store/edit',
                    del_url: 'store/del',
                    multi_url: 'store/multi',
                    table: 'store',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'store_name', title: __('Store_name')},
                        {field: 'cat_store', title: __('Cat_store')},
                        {field: 'ownerid', title: __('Ownerid')},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'address', title: __('Address')},
                        {field: 'ctime', title: __('Ctime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'state', title: __('State')},
                        {field: 'provinceid', title: __('Provinceid')},
                        {field: 'cityid', title: __('Cityid')},
                        {field: 'areaid', title: __('Areaid')},
                        {field: 'pingimages', title: __('Pingimages'), formatter: Table.api.formatter.images},
                        {field: 'level', title: __('Level')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 's_time', title: __('S_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'e_time', title: __('E_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'x_veidoo', title: __('X_veidoo')},
                        {field: 'y_veidoo', title: __('Y_veidoo')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});